package cn.edu.cqupt.cxcy.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.cqupt.cxcy.dto.InvestorImpl;
import cn.edu.cqupt.cxcy.model.Project;
import cn.edu.cqupt.cxcy.model.ProjectPage;

/**
 * 管理员后台主页
 * @author yinxu
 * @date 2015年10月17日
 */
public class InveIndex extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
		
		//super.doPost(request, response);
		
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	/*	request.setCharacterEncoding("utf-8");
		String pagenow1=request.getParameter("projecttype");
		response.setContentType("text/html;charset=utf-8");
         InvestorImpl a=new InvestorImpl();
        int sumofproject=a.SumOfProject();
         request.setAttribute("sumofall",sumofproject);
         System.out.println(pagenow1);

 		int pt_id_dianzi=new InvestorImpl().returnPt_id("\'digical\'");
 		int shengwu=new InvestorImpl().returnPt_id("\'shengwuinfo\'");
 		int canying=new InvestorImpl().returnPt_id("\'food\'");
 		int business=new InvestorImpl().returnPt_id("\'shangwu\'");	
 		int others=new InvestorImpl().returnPt_id("\'qita\'");
 		Map<String,String> allinfoofsum=new HashMap<String,String>();
 		allinfoofsum.put("all",Integer.toString(new InvestorImpl().SumOfProject()) );
 		allinfoofsum.put("dianzi", Integer.toString(new InvestorImpl().ReturnSumofAlltype(pt_id_dianzi)));
 		allinfoofsum.put("canying", Integer.toString(new InvestorImpl().ReturnSumofAlltype(canying)));
 		allinfoofsum.put("shangwu", Integer.toString(new InvestorImpl().ReturnSumofAlltype(business)));
 		allinfoofsum.put("qita", Integer.toString(new InvestorImpl().ReturnSumofAlltype(others)));
 		allinfoofsum.put("shengwu", Integer.toString(new InvestorImpl().ReturnSumofAlltype(shengwu)));
 		List<Project> allproject=new InvestorImpl().FirstOpenOfProjectOfSelf();
 		List<Project> alloffood=new InvestorImpl().TypeOfAll(canying);
 		List<Project> shengwuinfo=new InvestorImpl().TypeOfAll(shengwu);
 		List<Project> allodbusiness=new InvestorImpl().TypeOfAll(business);
 		List<Project> allofqita=new InvestorImpl().TypeOfAll(others);
 		List<Map<String,String>> allshow=new ArrayList<Map<String,String>>();
 		for(int i=0;i<allproject.size();i++)
 		{
 			Project one=allproject.get(i);
 			
 		
 		Map<String,String> map=new HashMap<String,String>();
 		map.put("pro_id", String.valueOf(one.getP_id()));
 		map.put("teamname", new InvestorImpl().returnTeamName(one.getTe_id()));
 		map.put("projectname",one.getP_name() );
 		map.put("account",one.getP_acount());
 		
 			allshow.add(map);
 		}
 		int firstpagesum=1;
 		if(allshow.size()%4==0)
 			firstpagesum=allshow.size()/4;
 		else
 			firstpagesum=(allshow.size()/4)+1;
 		ProjectPage page=new ProjectPage(firstpagesum,1,4);
 		List<Map<String,String>> alltopage=new ArrayList<Map<String,String>>();
 		Map<String,String> middle=new HashMap<String,String>();
 		for(int i=(page.getPagenow()-1)*4;i<=4*page.getPagenow()-1;i++)
 		{
 			if(i<=allshow.size()-1)
 			{middle=allshow.get(i);
 			alltopage.add(middle);}
 			
 			
 		}
 		String projectType=request.getParameter("projecttype");
 		System.out.println(projectType);
 		if(projectType!=null)
 		{		 if("pro_all".equals(projectType))
  	         {   
  	    	
  	    	String pagenow=request.getParameter("pagenow");
  	    	
  	    	if(pagenow!=null)
  	    		page.setPagenow(Integer.parseInt(pagenow));
  	    	//System.out.println(all.getPagenow());
  	    	String type=request.getParameter("type");
  	    	if(type!=null)
  	    	{if("up".equals(type))
  	    		page.setPagenow(page.getPagenow()-1);
  	    		if("down".equals(type))
  	    			page.setPagenow(page.getPagenow()+1);
  	    	}
  	    	for(int i=(page.getPagenow()-1)*4;i<=4*page.getPagenow()-1;i++)
  	 		{
  	 			if(i<=allshow.size()-1)
  	 			{middle=allshow.get(i);
  	 			alltopage.add(middle);}

  	 		}
  	    }
 	    if("pro_dian".equals(projectType))
 	    {    if(new InvestorImpl().ReturnSumofAlltype(pt_id_dianzi)%4==0)
	 			firstpagesum=new InvestorImpl().ReturnSumofAlltype(pt_id_dianzi)/4;
	 		else
	 			firstpagesum=(new InvestorImpl().ReturnSumofAlltype(pt_id_dianzi)/4)+1;
	    	
	    	page.setPagesum(firstpagesum);
  	    	
  	    	String pagenow=request.getParameter("pagenow");
  	    	  allproject=new InvestorImpl().TypeOfAll(pt_id_dianzi);
  	    	if(pagenow!=null)
  	    		page.setPagenow(Integer.parseInt(pagenow));
  	    	//System.out.println(all.getPagenow());
  	    	String type=request.getParameter("type");
  	    	if(type!=null)
  	    	{if("up".equals(type))
  	    		page.setPagenow(page.getPagenow()-1);
  	    		if("down".equals(type))
  	    			page.setPagenow(page.getPagenow()+1);
  	    	}
  	    	for(int i=(page.getPagenow()-1)*4;i<=4*page.getPagenow()-1;i++)
  	 		{
  	 			if(i<=allshow.size()-1)
  	 			{middle=allshow.get(i);
  	 			alltopage.add(middle);}
  	 		}
  	    	
 	    }
 	   if("pro_qi".equals(projectType))
 	  {   
 		  if(new InvestorImpl().ReturnSumofAlltype(others)%4==0)
	 			firstpagesum=new InvestorImpl().ReturnSumofAlltype(others)/4;
	 		else
	 			firstpagesum=(new InvestorImpl().ReturnSumofAlltype(others)/4)+1;
	    	
	    	page.setPagesum(firstpagesum);
	    	
	    	String pagenow=request.getParameter("pagenow");
	    	System.out.println(111);
	    	  allproject=new InvestorImpl().TypeOfAll(others);
	    	if(pagenow!=null)
	    		page.setPagenow(Integer.parseInt(pagenow));
	    	//System.out.println(all.getPagenow());
	    	String type=request.getParameter("type");
	    	if(type!=null)
	    	{if("up".equals(type))
	    		page.setPagenow(page.getPagenow()-1);
	    		if("down".equals(type))
	    			page.setPagenow(page.getPagenow()+1);
	    	}
	    	for(int i=(page.getPagenow()-1)*4;i<=4*page.getPagenow()-1;i++)
	 		{
	 			if(i<=allshow.size()-1)
	 			{middle=allshow.get(i);
	 			alltopage.add(middle);}
	 		}
 	    }
 	  if("pro_can".equals(projectType))
 	  {   
 		  if(new InvestorImpl().ReturnSumofAlltype(canying)%4==0)
	 			firstpagesum=new InvestorImpl().ReturnSumofAlltype(canying)/4;
	 		else
	 			firstpagesum=(new InvestorImpl().ReturnSumofAlltype(canying)/4)+1;
	    	
	    	page.setPagesum(firstpagesum);
	    	
	    	String pagenow=request.getParameter("pagenow");
	    	  allproject=new InvestorImpl().TypeOfAll(canying);
	    	if(pagenow!=null)
	    		page.setPagenow(Integer.parseInt(pagenow));
	    	//System.out.println(all.getPagenow());
	    	String type=request.getParameter("type");
	    	if(type!=null)
	    	{if("up".equals(type))
	    		page.setPagenow(page.getPagenow()-1);
	    		if("down".equals(type))
	    			page.setPagenow(page.getPagenow()+1);
	    	}
	    	for(int i=(page.getPagenow()-1)*4;i<=4*page.getPagenow()-1;i++)
	 		{
	 			if(i<=allshow.size()-1)
	 			{middle=allshow.get(i);
	 			alltopage.add(middle);}
	 		}
	    }
		if("pro_sheng".equals(projectType))
  {   
		 	
			  if(new InvestorImpl().ReturnSumofAlltype(shengwu)%4==0)
		 			firstpagesum=new InvestorImpl().ReturnSumofAlltype(shengwu)/4;
		 		else
		 			firstpagesum=(new InvestorImpl().ReturnSumofAlltype(shengwu)/4)+1;
		    	
		    	page.setPagesum(firstpagesum);
	  	    	
	  	    	String pagenow=request.getParameter("pagenow");
	  	    	  allproject=new InvestorImpl().TypeOfAll(shengwu);
	  	    	if(pagenow!=null)
	  	    		page.setPagenow(Integer.parseInt(pagenow));
	  	    	//System.out.println(all.getPagenow());
	  	    	String type=request.getParameter("type");
	  	    	if(type!=null)
	  	    	{if("up".equals(type))
	  	    		page.setPagenow(page.getPagenow()-1);
	  	    		if("down".equals(type))
	  	    			page.setPagenow(page.getPagenow()+1);
	  	    	}
	  	    	for(int i=(page.getPagenow()-1)*4;i<=4*page.getPagenow()-1;i++)
	  	 		{
	  	 			if(i<=allshow.size()-1)
	  	 			{middle=allshow.get(i);
	  	 			alltopage.add(middle);}
	  	 		}
  	    }
	if("pro_shang".equals(projectType))
	 {   
		  if(new InvestorImpl().ReturnSumofAlltype(business)%4==0)
	 			firstpagesum=new InvestorImpl().ReturnSumofAlltype(business)/4;
	 		else
	 			firstpagesum=(new InvestorImpl().ReturnSumofAlltype(business)/4)+1;
	    	
	    	page.setPagesum(firstpagesum);
	    	
	    	String pagenow=request.getParameter("pagenow");
	    	  allproject=new InvestorImpl().TypeOfAll(business);
	    	if(pagenow!=null)
	    		page.setPagenow(Integer.parseInt(pagenow));
	    	//System.out.println(all.getPagenow());
	    	String type=request.getParameter("type");
	    	if(type!=null)
	    	{if("up".equals(type))
	    		page.setPagenow(page.getPagenow()-1);
	    		if("down".equals(type))
	    			page.setPagenow(page.getPagenow()+1);
	    	}
	    	for(int i=(page.getPagenow()-1)*4;i<=4*page.getPagenow()-1;i++)
	 		{
	 			if(i<=allshow.size()-1)
	 			{middle=allshow.get(i);
	 			alltopage.add(middle);}
	 		}
 		}
 		}
 		
 		request.setAttribute("pro_show",alltopage );
 		request.setAttribute("pageinfoofall", page);
 		request.setAttribute("allinfoofsum", allinfoofsum);
	request.getRequestDispatcher("investor.jsp").forward(request, response);*/
 		}
 		 

}
